package com.econ.powercloud.ems.controller;

import com.econ.powercloud.common.base.facade.pojo.MsgResult;
import com.econ.powercloud.ems.service.biz.UserOperateTokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author : zj
 * @Description : 用户操作权限
 * @Date : 2021/8/13 14:41
 * @Modified by : zj
 */
@RestController
@Api(tags ="用户操作权限")
@RequestMapping(value = "/api/v2/userOperate")
public class UserOperateTokenController {

    @Autowired
    UserOperateTokenService userOperateTokenService;

    /**
     * 用户操作密码校验
     */
    @PostMapping(value = "verifyForPassword")
    @ApiOperation(value="用户操作密码校验", notes="用户操作密码校验")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "password", value = "密码", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "validTime", value = "有效时间（时间戳）", required = true, dataType = "Long")
    })
    public MsgResult verifyForPassword(@RequestParam(value = "password") String password,
                                       @RequestParam(value = "validTime") Long validTime) {

        return userOperateTokenService.verifyForPassword(password,validTime);
    }

    /**
     * 修改用户操作密码
     */
    @PutMapping(value = "updatePassword")
    @ApiOperation(value="修改用户操作密码", notes="修改用户操作密码")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "oldPassword", value = "旧密码", required = true, dataType = "Long"),
            @ApiImplicitParam(paramType="query", name = "newPassword", value = "新密码", required = true, dataType = "Long")
    })
    public MsgResult updatePasswordForUserName(@RequestParam(value = "oldPassword") String oldPassword,
                                       @RequestParam(value = "newPassword") String newPassword) {

        return userOperateTokenService.updatePasswordForUserName(oldPassword,newPassword);
    }


}
